package com.service.utils;

import com.system.entity.LoginUser;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.stereotype.Component;

/**
 * @author liuxuhuang
 * @date 2023年04月18日 21:58
 * @desc
 */
@Component
public class SecurityUtil {

    /**
     * 获取登录用户id
     *
     * @param context
     * @return
     */
    public long getUserId(SecurityContext context) {
        LoginUser loginUser = (LoginUser) context.getAuthentication().getPrincipal();
        return loginUser.getUser().getId();
    }


}
